package com.dehui.traders.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.TextAppearanceSpan;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.dehui.traders.R;
import com.dehui.traders.bean.RankBean;
import com.dehui.traders.widgets.BaseViewHolder;
import com.dehui.traders.widgets.CommonAdapter;

import java.util.List;

/**
 * Created by hqq on 18.4.10.
 */

public class RankListAdapter extends CommonAdapter<RankBean>{

    public RankListAdapter(Context context, List<RankBean> mDatas, int itemLayoutId) {
        super(context, mDatas, itemLayoutId);
    }

    @Override
    public void convert(BaseViewHolder helper, RankBean item, int position) {
        TextView tvTitle = helper.getView(R.id.tv_title);
        ListView lvDetail = helper.getView(R.id.lv_rank_detail);
        tvTitle.setText(item.title);

        List<RankBean.RankDetail> detailList = item.rankDetailList;

        CommonAdapter<RankBean.RankDetail> detailCommonAdapter = new CommonAdapter<RankBean.RankDetail>(mContext, detailList, R.layout.list_item_rank_detail_market) {
            @Override
            public void convert(BaseViewHolder helper, RankBean.RankDetail item, int position) {
                TextView tvName = helper.getView(R.id.tv_name);
                TextView tvNewest = helper.getView(R.id.tv_newest);
                TextView tvZdf = helper.getView(R.id.tv_zdf);
                TextView tvZde = helper.getView(R.id.tv_zde);

                SpannableString styledText = new SpannableString(item.name);
                styledText.setSpan(new TextAppearanceSpan(mContext, R.style.style_title_0), 0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                styledText.setSpan(new TextAppearanceSpan(mContext, R.style.style_title_1), 4, item.name.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                tvName.setText(styledText, TextView.BufferType.SPANNABLE);
                tvNewest.setText(item.newest);
                tvNewest.setTextColor(Color.RED);
                tvZdf.setText(item.zdf);
                tvZdf.setTextColor(Color.RED);
                tvZde.setText(item.zde);
                tvZde.setTextColor(Color.RED);

            }
        };
        lvDetail.setAdapter(detailCommonAdapter);
    }
}
